package com.rc.evcharger.service.member;

import com.rc.evcharger.mapper.member.MemberCardMapper;
import com.rc.evcharger.model.member.MemberCard;
import com.rc.evcharger.model.member.MemberCardExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Create by Yang on 2019/11/6
 */
@Service
public class MemberCardServiceImpl implements MemberCardService {

    @Autowired
    private MemberCardMapper memberCardMapper;


    @Override
    public MemberCardMapper getMapper() {
        return memberCardMapper;
    }


    @Override
    public MemberCard selectMemberId(Long memberId) {

        MemberCardExample memberCardExample = new MemberCardExample();
        memberCardExample.createCriteria().andMemberIdEqualTo(memberId);

        List<MemberCard> memberCards = memberCardMapper.selectByExample(memberCardExample);
        if (CollectionUtils.isEmpty(memberCards)) {
            return null;
        }

        return memberCards.get(0);
    }

    @Override
    public MemberCard selectByCardNo(String card) {
        MemberCardExample memberCardExample = new MemberCardExample();
        memberCardExample.createCriteria().andCardNoEqualTo(card).andOperateStatusEqualTo("1");

        List<MemberCard> memberCards = memberCardMapper.selectByExample(memberCardExample);
        if (CollectionUtils.isEmpty(memberCards)) {
            return null;
        }

        return memberCards.get(0);
    }


}
